package com.stx.yangyang;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class DeserializeDemo {
    public static void main(String[] args) {
        try {
            // 创建文件输入流，读取序列化的文件
            FileInputStream fis = new FileInputStream("src/com/stx/yangyang/user.txt");

            // 创建对象输入流
            ObjectInputStream ois = new ObjectInputStream(fis);

            // 从文件中反序列化User对象
            User user = (User) ois.readObject();

            // 关闭流
            ois.close();
            fis.close();

            System.out.println("User对象反序列化完成！");
            System.out.println("反序列化得到的对象: " + user);
            System.out.println("姓名: " + user.getName());
            System.out.println("年龄: " + user.getAge());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}